package com.heyun.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.heyun.bean.HeyunSalesPlan;
import com.heyun.dao.SalesPlanDao;
import com.heyun.service.SalesPlanService;
@Service
public class SalesPlanServiceImpl implements SalesPlanService {

	@Autowired
	private SalesPlanDao  salesplandao;
	@Override
	public  Map<String,Object> listSalsPlan(int currentPage) {
		PageHelper.startPage(currentPage,3);//每一页显示三条数据
		//获取所有销售计划的集合
		List<HeyunSalesPlan> hsplist=salesplandao.listSalsPlan();
		PageInfo<HeyunSalesPlan> p=new PageInfo<HeyunSalesPlan>(hsplist);
		for(HeyunSalesPlan hsp:hsplist){
			System.out.println("最后操作时间是====="+hsp.getFinalOperTime());
			System.out.println("销售计划内容是====="+hsp.getSalesPlanContent());
		}
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("hsplist", hsplist);
		map.put("totalPage", p.getPages());
		System.out.println("==========进来了没======="+currentPage);
		System.out.println("总页数是==="+p.getPages());
		return map;
	}
	@Override
	public int saveSalesPlan(HeyunSalesPlan hsp) {
		int result=salesplandao.saveSalesPlan(hsp);
		return result;
	}

	@Override
	public int updateSalesPlanById(HeyunSalesPlan hsp) {
		int result=salesplandao.updateSalsPlanById(hsp);
		return result;
	}

	@Override
	public int deleteSalesPlan(int salesPlanId) {
	    
		int result=salesplandao.deleteSalesPlan(salesPlanId);
		return result;
	}
   //提交销售计划 其实就是讲销售计划的状态改为已提交
	@Override
	public int updateSalesPlanStateById(int salesPlanId) {
		int result=salesplandao.updateSalesPlanStateById(salesPlanId);
		return result;
	}

	@Override
	public HeyunSalesPlan selectSalesPlanById(int salesPlanId) {
		// TODO Auto-generated method stub
		HeyunSalesPlan hsp=salesplandao.selectSalesPlanById(salesPlanId);
		return hsp;
	}

	@Override
	public  Map<String,Object> findSalesPlanByMonth(int currentPage,String month) {
		PageHelper.startPage(currentPage,3);//每一页显示三条数据
		List<HeyunSalesPlan> splist=salesplandao.findSalesPlanByMonth(month);
		PageInfo<HeyunSalesPlan> p=new PageInfo<HeyunSalesPlan>(splist);
		for(HeyunSalesPlan hsp:splist){
			System.out.println("最后操作时间是====="+hsp.getFinalOperTime());
			System.out.println("销售计划内容是====="+hsp.getSalesPlanContent());
		}
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("splist", splist);
		map.put("totalPage", p.getPages());
		return map;
	}
	
	@Override
	public void deleteBatchSalesPlan(List<Integer> ids) {
		// TODO Auto-generated method stub
		salesplandao.deleteBatchSalesPlan(ids);
	}



}
